'''
selenium可以执行JavaScript代码，使用execute_script("JavaScript代码")
JavaScript代码：
1）操作页面的滚动条
    window.scrollTo(x,y)  x,y最小值为0
    x,y有个最大界限值，为网页的实际大小
    document.body.scrollHeight  网页的高度
    document.body.scrollWidth  网页的宽度
2）设置样式（显示，隐藏样式）
    style="display:none"
    style="visibility:hidden"
  javascript代码：
    execute_script("arguments[0].setAttribute('style','display:none');")

'''

import time


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver = webdriver.Edge()
driver.get("http://www.baidu.com")
time.sleep(1)

# 修改窗口的大小
driver.set_window_size(600,500)
time.sleep(3)
# 向右100px
driver.execute_script("window.scrollTo(100,0)")
time.sleep(3)
# 向下200px
driver.execute_script("window.scrollTo(100,200)")
time.sleep(3)
# 滑动到最右边
driver.execute_script("window.scrollTo(document.body.scrollWidth,200)")
time.sleep(3)
# 滑动到最下边
driver.execute_script("window.scrollTo(document.body.scrollWidth,document.body.scrollHeight)")
time.sleep(1)

# 切换到然知系统
driver.get("http://127.0.0.1/ranzhi/www")
time.sleep(3)

input1 = driver.find_element("id","account")
driver.execute_script("arguments[0].setAttribute('style','display:none');",input1)
time.sleep(3)
try:
    input1.send_keys("admin")
except Exception as e:
    print(e)

# driver.execute_script("arguments[0].setAttribute('style','display:block');",input1)
driver.execute_script("arguments[0].removeAttribute('style','display:none');",input1)
time.sleep(30)